package org.example.store.controller;

import org.example.store.dao.StoreDao;
import org.example.store.entity.StoreEntity;
import org.example.store.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 门店表
 *
 * @author Amadeus
 * @email 313300182@qq.com
 * @date 2022-01-30 14:05:19
 */
@RestController
@RequestMapping("/store")
public class StoreController {
    @Autowired
    private StoreService storeService;
    @Resource
    private StoreDao storeDao;

    @GetMapping("/saveDao")
    public void saveDao() {
        List<StoreEntity> list = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            StoreEntity storeEntity = new StoreEntity();
            storeEntity.setName("s" + i);
            storeEntity.setCompanyId(i);
            list.add(storeEntity);
        }
        storeDao.insertBatchSomeColumn(list);
    }

    @GetMapping("/saveBatch")
    public boolean saveBatch() {
        List<StoreEntity> list = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            StoreEntity storeEntity = new StoreEntity();
            storeEntity.setName("s" + i);
            storeEntity.setCompanyId(i);
            list.add(storeEntity);
        }
        return storeService.saveBatch(list);
    }

    @GetMapping("/queryById")
    public StoreEntity getStore() {
        return storeService.getById(1);
    }

    @GetMapping("/save")
    public boolean save() {
        StoreEntity storeEntity = new StoreEntity();
        storeEntity.setName("s");
        storeEntity.setCompanyId(1);
        storeService.save(storeEntity);
        return true;
    }

}
